home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -coverdisks- / 126a / football / user / updateschedulescores.rexx < prev    next >
OS/2 REXX Batch file  |  1999-05-22  |  13KB  |  456 lines

  1. /* ***********************************************************************
  2.  
  3.   UPDATE SCHEDULE FILE PROGRAM FOR FOOTBALL REXX SUITE
  4.   ----------------------------------------------------
  5.                    Copyright  Mark Naughton 1998
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  
  11.  1.0       011098   Created. Found problem where the updates are not
  12.                     successfully made - fixed. Updated messages.
  13.  1.1       050599   Added code to check the schedule file to see if it
  14.                     contains the right number of matches for the number of
  15.                     teams playing a specified number of times. Added
  16.                     support for playing an odd number of times and for
  17.                     schedules for teams playing more than twice.
  18.  
  19. **************************************************************************
  20.  
  21. Procedure
  22. ---------
  23.  
  24. 1. Check files exist. Get schedule definition filename from '.df' file.
  25. 2. Read specified schedule definition file. Check schedule contains the
  26.    right number of matches before proceeding.
  27. 3. Read schedules and store dates/weeks.
  28. 4. Give error if the number of teams does not equal the number of lines in
  29.    the schedule file.
  30. 5. Write the dates/weeks to a file then use an external program to sort
  31.    them, writing back to the file.
  32. 6. Read dates into array and delete file.
  33. 7. Format dates array with season start date.
  34. 8. Format and write '.sf' files.
  35. 9. Read all data from Learn (without '*') into an array. Close file.
  36. 10.Open Schedule file and read into an array. Close file.
  37. 11.Update Schedule array with data from Learn but only if a match hasn't
  38.    been played.
  39. 12.Write to Schedule file. Close file. Exit.
  40.  
  41. ************************************************************************** */
  42. PARSE ARG league_file
  43.  
  44. version      = 1
  45. league_file  = "Data/" || strip(league_file)
  46. input_file   = '.df'
  47. input2_file  = '.schd'
  48. input3_file  = '.sflearn'
  49. output_file  = '.sf'
  50. title        = '*LEAGUE_NAME='
  51. autosched    = "*AUTOSCHD="
  52. playother    = '*PLAY_OTHER='
  53. teams.       = '???'
  54. dateweeks.   = '???'
  55. tdateweeks.  = '???'
  56. schedules2.  = '???'
  57. schedules4.  = '???'
  58. schedules6.  = '???'
  59. schedules8.  = '???'
  60. schedules0.  = '???'
  61. selines.     = '???'
  62. sdlines.     = '???'
  63. autos        = 0
  64. tcount       = 0
  65. ttc          = 0
  66. separator    = '*'
  67. not_played   = '__   __'
  68. months       = "January February March April May June July August September October November December"
  69.  
  70.  
  71. if exists(league_file || input_file) = 0 then exit
  72.  
  73. tcount = 0
  74. if open(datafile,league_file || input_file,'r') then do
  75.    do while ~eof(datafile)
  76.       line = readln(datafile)
  77.       line = strip(line)
  78.       if pos(separator,line) > 0 then do
  79.          if pos(autosched,line) > 0 then do
  80.             autofile = delstr(line,1,10)
  81.             autos = 1
  82.          end
  83.          if pos(title,line) > 0 then do
  84.             parse var line "*LEAGUE_NAME=" league_title
  85.             league_title = strip(league_title)
  86.          end
  87.          if pos(playother,line) > 0 then
  88.             playo = delstr(line,1,12)
  89.  
  90.        end
  91.        if pos(separator,line) = 0 & line ~="" then do
  92.             tcount = tcount + 1
  93.             teams.tcount = line
  94.        end
  95.    end
  96.    close(datafile)
  97. end
  98. else do
  99.    say
  100.    say "ERROR :    (UpdateScheduleScores)"
  101.    say
  102.    say "Cannot open '"league_file || input_file"' for reading."
  103.    exit
  104. end
  105.                                           /* Automatic Schedule creation */
  106. if autos = 1 then do
  107.  
  108.    if exists("Data/"autofile||input2_file) = 0 then do
  109.       say
  110.       say "ERROR :    (UpdateScheduleScores)"
  111.       say
  112.       say "Cannot find 'Data/"autofile||input2_file"'."
  113.       exit
  114.    end
  115.  
  116.    ct = 0
  117.    sct2= 0
  118.    sct4= 0
  119.    sct6= 0
  120.    sct8= 0
  121.    sct0= 0
  122.    weeks = 0
  123.    dates = 0
  124.    sch = 1
  125.  
  126.  
  127.    if open(datafile,"Data/"autofile||input2_file,'r') then do
  128.       mkct = ((tcount - 1) * playo) * (tcount/2)
  129.       kmct = 0
  130.       do while ~eof(datafile)
  131.          line = readln(datafile)
  132.          if line ~= '' & pos(separator,line) = 0 then do
  133.             counter = words(line)
  134.             do i=1 to counter
  135.                if word(line,i) ~= 0 then
  136.                   kmct = kmct + 1
  137.             end
  138.          end
  139.       end
  140.       close(datafile)
  141.    end
  142.    else do
  143.       say
  144.       say "ERROR :    (UpdateScheduleScores)"
  145.       say
  146.       say "Cannot find 'Data/"autofile||input2_file"' for reading."
  147.       say
  148.       say
  149.       say "The definition file, '"league_file || input_file"' has been created."
  150.       exit
  151.    end
  152.    if mkct ~= kmct then do
  153.       say
  154.       say "ERROR :    (UpdateScheduleScores)"
  155.       say
  156.       say "UpdateScheduleScores has found that the schedule file 'Data/"autofile||input2_file"'"
  157.       say "does not contain the correct number matches for "tcount" teams to play each other"
  158.       say playo" times. It contains "kmct" matches, where as it should contain "mkct" matches."
  159.       say "You will have to edit the schedule file or change the settings required when"
  160.       say "recreating the league or before running this program again."
  161.       exit
  162.    end
  163.  
  164.    if open(datafile,"Data/"autofile||input2_file,'r') then do
  165.       do while ~eof(datafile)
  166.          line = readln(datafile)
  167.          if pos("*WEEKS",line) then do
  168.             weeks=1
  169.          end
  170.          if pos("*DATES=",line) then do
  171.             startdate=substr(line,8,8)
  172.             dates = 1
  173.          end
  174.          if pos("*NEXT",line) > 0 then sch = sch + 1
  175.          if line ~= '' & pos(separator,line) = 0 then do
  176.             if sch = 1 then do
  177.                sct2 = sct2 + 1
  178.                schedules2.sct2 = line
  179.             end
  180.             if sch = 2 then do
  181.                sct4 = sct4 + 1
  182.                schedules4.sct4 = line
  183.             end
  184.             if sch = 3 then do
  185.                sct6 = sct6 + 1
  186.                schedules6.sct6 = line
  187.             end
  188.             if sch = 4 then do
  189.                sct8 = sct8 + 1
  190.                schedules8.sct8 = line
  191.             end
  192.             if sch = 5 then do
  193.                sct0 = sct0 + 1
  194.                schedules0.sct0 = line
  195.             end
  196.             counter = words(line)
  197.             do i=1 to counter
  198.                sdate = word(line,i)
  199.                if sdate = 0 then
  200.                   iterate
  201.                if ct = 0 then do
  202.                   ct = ct + 1
  203.                   dateweeks.ct = sdate
  204.                end
  205.                else do
  206.                   ij = 0
  207.                   do j=1 to ct
  208.                      if sdate = dateweeks.j then do
  209.                         ij = 1
  210.                         leave
  211.                      end
  212.                   end
  213.                   if ij = 0 then do
  214.                      ct = ct + 1
  215.                      dateweeks.ct = sdate
  216.                   end
  217.                end
  218.             end
  219.          end
  220.       end
  221.       close(datafile)
  222.    end
  223.    else do
  224.       say
  225.       say "ERROR :    (UpdateScheduleScores)"
  226.       say
  227.       say "Cannot find 'Data/"autofile||input2_file"' for reading."
  228.       exit
  229.    end
  230.    sct = (sct2 + sct4 + sct6 + sct8 + sct0) / sch
  231.  
  232.    if counter ~= sct then do
  233.       say
  234.       say "ERROR :    (UpdateScheduleScores)"
  235.       say
  236.       say "The schedule definition file specified only has "sct" scheduled"
  237.       say "teams whereas there are "tcount" teams in the league."
  238.       say
  239.       say "Creation of files aborted. Re-specify correct schedule."
  240.       say
  241.       say "Definition file    :  "league_file||input_file
  242.       say "Schedule Def. file :  Data/"autofile||input2_file
  243.       say
  244.       exit
  245.    end
  246.  
  247.    if open(datafile2,"RAM:schd.temp",'w') then do
  248.       do j=1 to ct
  249.          writeln(datafile2,dateweeks.j)
  250.       end
  251.       close(datafile2)
  252.    end
  253.    else do
  254.       say
  255.       say "ERROR :    (UpdateScheduleScores)"
  256.       say
  257.       say "Cannot create temporary file in RAM:."
  258.       exit
  259.    end
  260.  
  261.    if weeks = 1 then
  262.       address command 'sort RAM:schd.temp RAM:schd.temp'
  263.    if dates = 1 then
  264.       address command 'Exec/SortWkDts'
  265.  
  266.    if open(datafile2,"RAM:schd.temp",'r') then do
  267.       do j=1 to ct
  268.          dateweeks.j = readln(datafile2)
  269.       end
  270.       close(datafile2)
  271.    end
  272.    else do
  273.       say
  274.       say "ERROR :    (UpdateScheduleScores)"
  275.       say
  276.       say "Cannot find te